<template>
  <div>
   <center>
   <el-button type="primary" @click="addBook">添加图书</el-button>
   </center>
    <el-table :data="books" style="width: 100%">
      <el-table-column prop="id" label="ID" width="180"></el-table-column>
      <el-table-column prop="title" label="书名" width="180"></el-table-column>
      <el-table-column prop="author" label="作者" width="180"></el-table-column>
      <el-table-column prop="copies" label="副本数量" width="180"></el-table-column>
      <el-table-column label="操作" width="180">
        <template slot-scope="scope">
          <el-button type="text" @click="deleteBook(scope.$index)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="书名">
        <el-input v-model="form.title"></el-input>
      </el-form-item>
      <el-form-item label="作者">
        <el-input v-model="form.author"></el-input>
      </el-form-item>
      <el-form-item label="副本数量">
        <el-input v-model="form.copies"></el-input>
      </el-form-item>
      <el-form-item>
       
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      books: [
        {"id": 1, "title": "Python编程", "author": "John Doe", "copies": 4},
        {"id": 2, "title": "历史的秘密", "author": "Jane Smith", "copies": 3},
        {"id": 3, "title": "宇宙探索", "author": "Emily Brown", "copies": 2},
        {"id": 4, "title": "健康生活", "author": "Mike Johnson", "copies": 5},
        {"id": 5, "title": "数学之美", "author": "Sarah Lee", "copies": 4},
        {"id": 6, "title": "艺术欣赏", "author": "David White", "copies": 3},
        {"id": 7, "title": "编程入门", "author": "Alice Green", "copies": 2},
        {"id": 8, "title": "科幻世界", "author": "Frank Black", "copies": 5},
        {"id": 9, "title": "自然奇观", "author": "Grace Blue", "copies": 4},
        {"id": 10, "title": "音乐之声", "author": "Tom Red", "copies": 3}
      ],
      form: {
        title: '',
        author: '',
        copies: ''
      }
    }
  },
  methods: {
    addBook() {
      const newBook = {
        id: this.books.length + 1,
        title: this.form.title,
        author: this.form.author,
        copies: parseInt(this.form.copies)
      }
      this.books.push(newBook)
      this.resetForm()
    },
    deleteBook(index) {
      this.books.splice(index, 1)
    },
    resetForm() {
      this.form.title = ''
      this.form.author = ''
      this.form.copies = ''
    }
  }
}
</script>
